﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:edra="http://www.microsoft.com/practices/referencearchitecture/services/03-08-2004/ReferenceArchitectureSection.xsd"
    xmlns:ba="http://www.microsoft.com/practices/referencearchitecture/services/05-21-2004/BusinessActionsDefinition.xsd"
    exclude-result-prefixes="xsl msxsl edra ba"
>
  <xsl:output method="xml" indent="yes" />

  <xsl:template match="/">

    <RuntimeConfiguration>

      <AssemblyLoadPath Path="C:\Projects\Akbank.InternetBanking.2010\Main\Source\Presentation\WebApplication.UI\Bin" />

      <Type Name="RequestMessage" Impl="VeriBranch.Common.MessageDefinitions.RequestMessage, VeriBranch.Common.MessageDefinitions" />
      <Type Name="ResponseMessage" Impl="VeriBranch.Common.MessageDefinitions.ResponseMessage, VeriBranch.Common.MessageDefinitions" />

      <Type Name="Container" Impl="OrganizationName.Factory.LifeTimeContracts.ContainerLifeTimeContract, OrganizationName" />
      <Type Name="Thread" Impl="OrganizationName.Factory.LifeTimeContracts.ThreadLifeTimeContract, OrganizationName" />

      <Instance Name="ResponseMessage" Impl="ResponseMessage">
        <LifeTimeContract Impl="Thread" />
      </Instance>

      <Instance Name="RequestMessage" Impl="RequestMessage">
        <LifeTimeContract Impl="Thread" />
        <Attribute Name="TransactionHeader">
          <Attribute Name="TransactionDefinition" />
          <Attribute Name="Result" />
        </Attribute>
      </Instance>

      <xsl:apply-templates />

    </RuntimeConfiguration>

  </xsl:template>

  <xsl:template match="configuration/referenceArchitecture/edra:settings/edra:handlers/edra:handler">
    <Type Name="{@name}" Impl="{@type}" />
  </xsl:template>

  <xsl:template match="configuration/pipelinesDefinition/edra:settings/edra:pipelines/edra:serviceImplementationPipelines/edra:pipeline">

    <Instance Name="{@serviceActionName}" Impl="ResponseMessage">

      <xsl:apply-templates select="edra:before/edra:handler" />

      <Invoke Name="ACTION_{@serviceActionName}" Method="BusinessActionCall">
        <Source Impl="{@serviceActionName}" />
        <Parameter Reference="RequestMessage" />
      </Invoke>

      <xsl:apply-templates select="edra:after/edra:handler" />

    </Instance>

  </xsl:template>

  <xsl:template name="BeforeHandlers" match="edra:before/edra:handler">
    <Invoke Name="BEFORE_HANDLER_{@handlerName}" Method="ExecuteHandler">
      <Source Impl="{@handlerName}" />
      <Parameter Reference="RequestMessage" />
      <Parameter Reference="ResponseMessage" />
    </Invoke>
  </xsl:template>

  <xsl:template name="AfterHandlers" match="edra:after/edra:handler">
    <Invoke Name="AFTER_HANDLER_{@handlerName}" Method="ExecuteHandler">
      <Source Impl="{@handlerName}" />
      <Parameter Reference="RequestMessage" />
      <Parameter Reference="ResponseMessage" />
    </Invoke>
  </xsl:template>

  <xsl:template match="configuration/businessActionsDefinition/ba:businessActions/ba:businessAction">
    <Type Name="{@serviceActionName}" Impl="{@type}" />
  </xsl:template>

</xsl:stylesheet>
